import Vue from 'vue'
import VueRouter from 'vue-router'

//axios
import axios from '../axios'

Vue.use(VueRouter)

const routes = [
	//用户路由
	{
		path: '/',
		name: 'News',
		component: () => import('../views/News.vue')
	},
	{//娱乐
		path: '/recreation',
		name: 'Recreation',
		component: () => import('../views/nav/Recreation.vue')
	},
	{//体育
		path: '/sports',
		name: 'Sports',
		component: () => import('../views/nav/Sports.vue')
	},
	{//军事
		path: '/military',
		name: 'Military',
		component: () => import('../views/nav/Military.vue')
	},
	{//国际
		path: '/internation',
		name: 'Internation',
		component: () => import('../views/nav/Internation.vue')
	},
	{//时政
		path: '/politics',
		name: 'Politics',
		component: () => import('../views/nav/Politics.vue')
	},
	{//科技
		path: '/science',
		name: 'Science',
		component: () => import('../views/nav/Science.vue')
	},
	{//文化
		path: '/culture',
		name: 'Culture',
		component: () => import('../views/nav/Culture.vue')
	},
	{//新闻内容
		path: '/news/:newsId',
		name: 'NewsDetail',
		component: () => import('../views/NewsDetail.vue')
	},
	//管理员路由
    {
        path: '/adminHome',
        name: 'Home',
        component: () => import('../views/Home.vue'),
		meta:{
			requireAuth: true
		},
        children: [
            {//子目录根目录
                path: '/',
                name: 'index',
				meta:{
					requireAuth: true
				},
                component: () => import('../views/Index.vue')
            },
            //
            {
                path: '/index',
                name: 'Index',
               meta:{
               	requireAuth: true
               },
                component: () => import('../views/Index.vue')
            },
            //
            {
                path: '/sys/admin',
                name: 'SysAdmin',
               meta:{
               	requireAuth: true
               },
                component: () => import('../views/sys/SysAdmin.vue')
            },
            //用户管理
            {
                path: '/sys/user',
                name: 'SysUser',
               meta:{
               	requireAuth: true
               },
                component: () => import('../views/sys/User.vue')
            },
            //文章管理
            {
                path: '/sys/news',
                name: 'SysNews',
               meta:{
               	requireAuth: true
               },
                component: () => import('../views/sys/News.vue')
            },
            //新增文章
            {
                path: '/sys/add/news',
                name: 'SysAddNews',
               meta:{
               	requireAuth: true
               },
                component: () => import('../views/sys/AddNews.vue')
            },
			//轮播图
            {
                path: '/sys/collapse',
                name: 'Collapse',
               meta:{
               	requireAuth: true
               },
                component: () => import('../views/sys/Collapse.vue')
            },
        ]
    },

    //管理员登录
    {
        path: '/admin',
        name: 'Admin',
        //懒加载
        component: () => import('../views/Admin.vue')
    },
	//用户登录
	{
	    path: '/login',
	    name: 'Login',
	    component: () => import('../views/Login.vue')
	},
	//用户注册
	{
	    path: '/register',
	    name: 'Register',
	    component: () => import('../views/Register.vue')
	},
	//用户个人空间
	{
	    path: '/user',
	    name: 'User',
		meta:{
			requireAuth: true
		},
	    component: () => import('../views/User.vue')
	},
	//修改个人信息
	{
	  path: '/user/setting',
	  name: 'Setting',
	  meta:{
	  	requireAuth: true
	  },
	  component: () => import('../views/user/Setting.vue'),
	  
		children: [
			{//默认路径
			  path: '/',
			  name: 'Minemsg',
			 meta:{
			 	requireAuth: true
			 },
			 component: () => import('../views/user/MineMessage.vue')
			},
			{//图片
			  path: '/user/mineimg',
			  name: 'Mineimg',
			 meta:{
			 	requireAuth: true
			 },
			 component: () => import('../views/user/MineImage.vue')
			},
			{//个人信息
			  path: '/user/minemsg',
			  name: 'Minemsg',
			  meta:{
			  	requireAuth: true
			  },
			  component: () => import('../views/user/MineMessage.vue')
			},
			{//密码
			  path: '/user/repass',
			  name: 'Repassword',
			  meta:{
			  	requireAuth: true
			  },
			  component: () => import('../views/user/RePassword.vue')
			},
		]
	},
	
	//--------------404-----------------
	    {
	      path: '/*',
	      name: 'error',
	      component: () => import('@/views/Error.vue')
	    }
]

const router = new VueRouter({
    mode: 'history',
    base: process.env.BASE_URL,
    routes
})

//动态获取路由
router.beforeEach((to, from, next) => {
    next()
})

export default router
